<?php
/**
*
* @author Blackpawn blackpawn666@hotmail.com - http://blackpawnsarchives.net
* @co_author GameCharmer admin@gamecharmer.com - http://gaming.gamecharmer.com
* @package Age of Dragons Mod :: ( Game Console Required )
* @version $Id: report.php 1.1.1 12-26-2009 Blackpawn
* @copyright (c) 2009 Blackpawns Archives
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
* @extra info
* This page will be used to display info back to the user after all the transaction made by the user.
* The reason I use this method is to help prevent users from button smashing and freshing the page.  
* If the user attempts to refresh the page after a transaction they will only be refreshing this report
* page which is fine in my book if they want to see the results over and over then let them but at least now
* they will not be causing problems for your system. This same idea can also be used in forum code to prevent
* double posts or in form posting scripts to prevent double entries as well. This method is not 100% fool proof
* but it does help. 
*/

/**
* @ignore
*/
define('GC_MOD', true);
define('IN_PHPBB', true);
define('AOD', true);

$phpbb_root_path =  '../../';
$templates_path = '../../../games/aod/templates/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/mods/game_console/gc_common.' . $phpEx);
include($phpbb_root_path . 'games/aod/common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Set custom language path
$user->set_custom_lang_path($phpbb_root_path.'games/aod/language/');

//load our language file
$user->add_lang('common');

// Now add the phpBB language path
$user->set_custom_lang_path($phpbb_root_path . 'language');

// Load the Game Console language file
$user->add_lang('mods/game_console');

if ($user->data['user_id'] == ANONYMOUS)
{
	login_box('', $user->lang['LOGIN']);
}

if ($user->data['is_bot'])
{
	redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
}

// Constants
$error_msgs = null;
$admin = 0;

// Vars
$cmd = request_var('cmd','');
$qid = request_var('qid', 0);
$start = request_var('start', 0);

// AOD Config
$quests_per_page = $aod_config['quests_per_page'];


// Gather some user info
$user_id = $user->data['user_id'];
$account_status = check_account_status($user_id);

if ($account_status == FALSE)
{
	redirect(append_sid("{$phpbb_root_path}/games/index.$phpEx"));
}

// Fetch kingdom data
$king = fetch_kingdom_data($user_id);
$admin_access = $king['admin_access'];
$kingdom_sponsor = $king['kingdom_sponsor'];
$kingdom_level = $king['kingdom_level'];
$kingdom_net = $king['kingdom_net'];
$kingdom_land = $king['kingdom_land'];
$kingdom_food = $king['kingdom_food'];
$kingdom_wood = $king['kingdom_wood'];
$kingdom_iron = $king['kingdom_iron'];
$kingdom_gold = $king['kingdom_gold'];
$kingdom_stamina = $king['kingdom_stamina'];
$kingdom_turns = $king['kingdom_turns'];
$kingdom_status = $king['kingdom_status'];

// Check to see if this user is a admin staff member
if ($user_id == 2 || $admin_access == 1)
{
	$admin = 1;
}

// Check kingdom status to see if this account is frozen
if($kingdom_status == 1)
{
	// Lets make sure the main admin can't be blocked
	if ($user_id <> 2){
		trigger_error($user->lang['FROZEN'] . back_link());
	}
}

// Clean out old reports
$db->sql_query(
"DELETE FROM " . AOD_REPORTS_TABLE ." 
WHERE user_id = $user_id 
AND seen = 1");
$db->sql_return_on_error(false);

$sql = "SELECT * 
FROM " . AOD_REPORTS_TABLE . "
WHERE user_id = $user_id
ORDER BY id DESC
LIMIT 1";
$result = $db->sql_query($sql);

if ($row = $db->sql_fetchrow($result))
{
	$rid 	= $row['id'];
	$report	= $row['report'];
	$link	= $row['link'];
	$date	= $row['date'];
}else{
	redirect(append_sid("{$phpbb_root_path}/games/aod/index.$phpEx"));
}
$db->sql_freeresult($result);


if(!$link)
{
	$link = 'javascript:history.go(-1);';
}
	
$return_link = '<a href="'.$link.'" class="xtext">Click Here to Return</a>';


// Update reports that haven't been seen
$db->sql_query(
"UPDATE " . AOD_REPORTS_TABLE ." 
SET seen = 1
WHERE user_id = $user_id");
$db->sql_return_on_error(false);
			
// Display an error messages to the user
$error_msgs = error_msgs($error_msgs);

$template->assign_vars(array(
	'REPORT'				=> $date.'<br /><br />'.$report,
	'RETURN_LINK' 			=> $return_link,
	)
);

include($phpbb_root_path . 'games/aod/includes/page_header.' . $phpEx);


// Output page
page_header($game_name.' - '.$user->lang['REPORT']);

$template->set_filenames(array(
	'body' => $templates_path.'report_body.html')
);

page_footer();
?>